package com.zggk.iroad.Distribution.distributionmx;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zggk.iroad.R;
import com.zggk.iroad.adapter.recycleview.LGRecycleViewAdapter;
import com.zggk.iroad.adapter.recycleview.LGViewHolder;
import com.zggk.iroad.mvp.MVPBaseActivity;
import com.zggk.iroad.util.NoScroolRecycle;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class DistributionMxActivity extends MVPBaseActivity<DistributionMxContract.View, DistributionMxPresenter> implements DistributionMxContract.View {


    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.cancle_button)
    TextView cancleButton;
    @Bind(R.id.cjdw_te)
    TextView cjdwTe;
    @Bind(R.id.cjdw_lay)
    LinearLayout cjdwLay;
    @Bind(R.id.lx_te)
    TextView lxTe;
    @Bind(R.id.lx_lay)
    LinearLayout lxLay;
    @Bind(R.id.cjsj_te)
    TextView cjsjTe;
    @Bind(R.id.cjsj_lay)
    LinearLayout cjsjLay;
    @Bind(R.id.szh_te)
    TextView szhTe;
    @Bind(R.id.szh_lay)
    LinearLayout szhLay;
    @Bind(R.id.tzh_te)
    TextView tzhTe;
    @Bind(R.id.tzh_lay)
    LinearLayout tzhLay;
    @Bind(R.id.xsfx_te)
    TextView xsfxTe;
    @Bind(R.id.xsfx_lay)
    LinearLayout xsfxLay;
    @Bind(R.id.bhlx_te)
    TextView bhlxTe;
    @Bind(R.id.bhlx_lay)
    LinearLayout bhlxLay;
    @Bind(R.id.bhmc_ed)
    TextView bhmcEd;
    @Bind(R.id.bhmc_lay)
    LinearLayout bhmcLay;
    @Bind(R.id.ygsl_te)
    TextView ygslTe;
    @Bind(R.id.ygsl_lay)
    LinearLayout ygslLay;
    @Bind(R.id.sgfs_te)
    TextView sgfsTe;
    @Bind(R.id.sgfs_lay)
    LinearLayout sgfsLay;
    @Bind(R.id.czfa_re)
    NoScroolRecycle czfaRe;
    @Bind(R.id.ygje_te)
    TextView ygjeTe;
    @Bind(R.id.ygje_lay)
    LinearLayout ygjeLay;
    @Bind(R.id.jhje_te)
    TextView jhjeTe;
    @Bind(R.id.jhje_lay)
    LinearLayout jhjeLay;
    @Bind(R.id.wxzj_te)
    TextView wxzjTe;
    @Bind(R.id.wxzj_lay)
    LinearLayout wxzjLay;
    @Bind(R.id.syzj_te)
    TextView syzjTe;
    @Bind(R.id.syzj_lay)
    LinearLayout syzjLay;
    private List<DistriCzBean.CZFAMXBean> Datas = new ArrayList<>();
    private LGRecycleViewAdapter<DistriCzBean.CZFAMXBean> adapter;

    @Override
    public void onRequestError(String msg) {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_distrimx;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        mPresenter.testinfo(DistributionMxActivity.this,getIntent().getStringExtra("RZID"));
        initAdapter();
        initView();
    }
    private void initView() {
        titleText.setText("审核派发");
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    @Override
    public void getDatas(List<DistriHhMxBean> distriHhMxBeans, List<DistriCzBean> distriCzBeans,List<DistriZjBean> distriZjBeans) {
        if (distriHhMxBeans != null && distriHhMxBeans.size() > 0) {
            cjdwTe.setText(distriHhMxBeans.get(0).getGYDWMC());
            lxTe.setText(distriHhMxBeans.get(0).getLXMC());
            cjsjTe.setText(distriHhMxBeans.get(0).getDCSJ());
            szhTe.setText(distriHhMxBeans.get(0).getQDZH());
            tzhTe.setText(distriHhMxBeans.get(0).getTJQDZH());
            xsfxTe.setText(distriHhMxBeans.get(0).getWZFX());
            bhlxTe.setText(distriHhMxBeans.get(0).getSHBW());
            bhmcEd.setText(distriHhMxBeans.get(0).getBHMC());
            ygslTe.setText(distriHhMxBeans.get(0).getYGSL());
        }
        if (distriCzBeans != null && distriCzBeans.size() > 0) {
            sgfsTe.setText(distriCzBeans.get(0).getCZFAMC());
            if (distriCzBeans.get(0).getCZFAMX()!=null&&distriCzBeans.get(0).getCZFAMX().size()>0){
                Datas.addAll(distriCzBeans.get(0).getCZFAMX());
                adapter.notifyDataSetChanged();
            }
        }
        if (distriZjBeans != null && distriZjBeans.size() > 0) {
            jhjeTe.setText(distriZjBeans.get(0).getJHZJ());
            wxzjTe.setText(distriZjBeans.get(0).getYXZJ());
            syzjTe.setText(distriZjBeans.get(0).getSYZJ());
        }

    }
    private void initAdapter() {
        LinearLayoutManager manager = new LinearLayoutManager(DistributionMxActivity.this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        czfaRe.setLayoutManager(manager);
        czfaRe.setHasFixedSize(true);
        czfaRe.setNestedScrollingEnabled(false);
        adapter = new LGRecycleViewAdapter<DistriCzBean.CZFAMXBean>(Datas) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_distri_czfa;
            }

            @Override
            public void convert(LGViewHolder holder, DistriCzBean.CZFAMXBean zCDBean, int position) {
                holder.setText(R.id.name_te, zCDBean.getXMMC());
                holder.setText(R.id.dj_te, zCDBean.getDJ());
                holder.setText(R.id.dw_te, "元/单价");
            }
        };
        czfaRe.setAdapter(adapter);
    }
}
